<?php
/**
 * Created by PhpStorm.
 * User: 李京蔚
 * Date: 2018/7/19
 * Time: 17:42
 */

namespace App\Http\Controllers\Common\Config;


use App\Http\Controllers\Common\ApiController;
use App\Models\Config;
use Illuminate\Http\Request;

class ConfigsController extends ApiController
{
    /**
     * @param Request $request
     * 功能：获取配置
     * GET: /api/public/config
     * @param string app
     * @param string key
     * @return mixed
     */
    public function select(Request $request)
    {
        $input = $request->only(['app', 'key']);
        $result = \Validator::make($input, [
            'app'   => 'required|string',
        ], [
            'app.required'       => 'app必须是一个字符串',
        ]);

        if($result->fails()){
            return $this->setStatusCode(30000)->message($result->errors()->first());
        }
        return $this->success(Config::gstByConfig($input));
    }
    /**
     *  功能：获取单个配置
     * GET: /api/public/config/selectOnce
     * @param app string
     * @param key string
     * @return mixed JSON { code: 错误码, message: 错误信息}
     */
    public function selectOnce(Request $request)
    {
        $input = $request->only(['app', 'key']);
        $result = \Validator::make($input, [
            'app'   => 'required|string',
            'key'   => 'required|string'
        ], [
            'app.required'       => 'app必须是一个字符串',
            'app.string'         => 'app必须是一个字符串',
            'key.required'       => 'key必须是一个字符串',
            'key.string'         => 'key必须是一个字符串',
        ]);

        if($result->fails()){
            return $this->responseFormat(30000, $result->errors()->first());
        }
        return $this->responseFormat(0, '',Config::gstByParamConfig($input));
    }
}